package com.until;

import android.widget.Spinner;
import android.widget.SpinnerAdapter;

public class Until {

	/**
	 * 根据key值, 设置spinner默认选中:
	 * @param spinner
	 * @param key
	 */
	public static void setSpinnerItemSelectedByKey(Spinner spinner,int key){
		SpinnerAdapter apsAdapter= spinner.getAdapter(); //得到SpinnerAdapter对象
		int k= apsAdapter.getCount();
		for(int i=0;i<k;i++){
			CItem spinnerItem = (CItem) apsAdapter.getItem(i);
			if (key == spinnerItem.GetID()) {
				spinner.setSelection(i,true);// 默认选中项
				break;
			}
		}
	} 
}
